package com.lpit.service.impl;

import com.lpit.service.SusceptibleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

@Service
@Slf4j
public class SusceptibleServiceImpl implements SusceptibleService {
    public static  final String ORDER_KEY = "ord:";

    @Resource
    private RedisTemplate redisTemplate;

    public void addOrder(){
        int keyId = ThreadLocalRandom.current().nextInt(100)+1;
        String serialNo = UUID.randomUUID().toString();

        String key = ORDER_KEY + keyId;
        String value = "敏感词" + serialNo;

        redisTemplate.opsForValue().set(key,value);

        log.info("***key:{}",key);
        log.info("***value:{}",value);
    }

    public String getOrderByid(Integer keyId){
        return (String) redisTemplate.opsForValue().get(ORDER_KEY+keyId);
    }
}
